﻿using Student2024.Model.EF;
using Student2024.Model.ViewModel;
using Student2024.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Student2024.UI.form
{
    /// <summary>
    /// 新建数据记录的类，用于创建新的学生记录
    /// </summary>
    public partial class FormCreate : Form
    {
        //服务层实例，用于处理业务逻辑
        private readonly StudentSystemService service = new StudentSystemService();
        //考试类型，区分新老高考
        private string examType;

        /// <summary>
        /// 构造函数，初始化并设置相关选项
        /// </summary>
        /// <param name="ExamType"></param>
        public FormCreate(string ExamType)
        {
            this.examType = ExamType;
            InitializeComponent();
            this.comboBoxObjectGroup.Items.Clear();
            //根据考试类型添加对应的选项组选项
            if (ExamType == "新高考")
            {
                comboBoxObjectGroup.Items.Add("物理组");
                comboBoxObjectGroup.Items.Add("历史组");
            }
            else if (ExamType == "老高考")
            {
                comboBoxObjectGroup.Items.Add("理科");
                comboBoxObjectGroup.Items.Add("文科");
            }
        }

        /// <summary>
        /// 取消事件处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 确定按钮的事件处理程序，创建新的学生记录并关闭窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            //创建学生记录模型、填充数据
            T001StudentCreateModel model = new T001StudentCreateModel()
            {
                Name = txtName.Text,
                Province = comboBoxProvince.Text,
                ExamType = examType,
                ObjectGroup = comboBoxObjectGroup.Text,
                SchoolName = txtSchoolName.Text,
                PhoneNum = txtPhoneNum.Text,
                Gender = comboBoxGender.Text,
            };
            //调用服务层方法创建学生记录
            service.Create(model);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
